#include "../begonia.h"
#include "boss_1_5.h"
#include "../base/scene.h"

boss_1_5::boss_1_5():boss(192.0,250.0,20.0,0.0,0.0,&f.head)
    {
        aimx=f.px;
        aimy=f.py;
    }
boss_1_5::boss_1_5(double tx,double ty,double tr,double tvx,double tvy,bullet *h):boss(tx,ty,tr,tvx,tvy,h)
    {
        tstop=-1.0;
    }
    void boss_1_5::clone(bullet *h)
    {
        new boss_1_5(x,y,r,vx,vy,h);
    }
    bool boss_1_5::move()
    {
        if((int)t/10>(int)tlast/10)
        {
            double dx,dy,theta,t1,t2,t3,t4;
            dx=aimx-f.px;
            dy=aimy-f.py;
            if(dx*dx+dy*dy<1e-9) theta=double(rand()%1000)/500.0*M_PI;
            else theta=atan2(dy,dx);
            t1=atan2(f.py,f.px);
            t2=atan2(f.py,f.px-scw);
            t3=atan2(f.py-sch,f.px-scw);
            t4=atan2(f.py-sch,f.px);
            if(theta<t3||theta>=t2) new bullet(scw,f.py+(scw-f.px)*tan(theta),10.0,cos(theta)*1.5,sin(theta)*1.5,&f.head);
            else if(theta<t4) new bullet(f.px+(sch-f.py)*tan(M_PI/2-theta),sch,10.0,cos(theta)*1.5,sin(theta)*1.5,&f.head);
            else if(theta<t1) new bullet(0,f.py-f.px*tan(theta),10.0,cos(theta)*1.5,sin(theta)*1.5,&f.head);
            else new bullet(f.px-f.py*tan(M_PI/2-theta),0,10.0,cos(theta)*1.5,sin(theta)*1.5,&f.head);
            aimx=f.px;
            aimy=f.py;
        }
        if(tstop>=0)
        {
            if(t>=tstop) {vx=vy=0.0;tstop=-1.0;}
        }
        else if((int)t>(int)tlast&&!(rand()%300))
        {
            double theta=atan2(f.py-y,f.px-x);
            vx=cos(theta)*5.0;vy=sin(theta)*5.0;
            tstop=t+10.0;
        }
        x+=vx*(t-tlast);y+=vy*(t-tlast);
        return true;
    }
